package com.wtwd.device.controller;


import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.dto.SynchronizationHeartRateDto;
import com.wtwd.device.model.dto.SynchronizationStepDto;
import com.wtwd.device.model.entity.DeviceHeartRate;
import com.wtwd.device.model.entity.DeviceStep;
import com.wtwd.device.model.entity.DeviceStepInfo;
import com.wtwd.device.model.vo.DeviceStepVo;
import com.wtwd.device.model.vo.ResultVO;
import com.wtwd.device.service.IDeviceStepInfoService;
import com.wtwd.device.service.IDeviceStepService;
import com.wtwd.device.util.DateUtils;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

@Api(tags = "4g设备上传步数")
@RequestMapping("/app-step")
@RestController
public class AppDeviceStepController {


    @Resource
    private IDeviceStepService deviceStepService;



    @ApiOperation("获取某一天的步数信息及步数详细信息(一般步数)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "date", value = "日期yyyyMMdd", required = true, dataType = "String"),
            @ApiImplicitParam(name = "id", value = "步数详细信息表主键id 默认不传查全天", required = false, dataType = "long")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getDayStepDataByTime")
    public ResultVO<DeviceStepVo> getDayStepDataByTime(@RequestParam String date, @RequestParam Long deviceId, @RequestParam(value = "id", required = false) Long id) {
        DeviceStepVo step = deviceStepService.getDayStepDataByTime(deviceId, id, date);
        return ResultVO.success(step);
    }

    @ApiOperation(value = "根据开始日期和结束日期获取步数信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long")
            , @ApiImplicitParam(name = "startDate", value = "开始日期,yyyyMMdd", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endDate", value = "结束日期,yyyyMMdd", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/daysStepInfo")
    public ResultVO<List<DeviceStep>> getDaysStepInfo(@RequestParam Long deviceId, @RequestParam String startDate, @RequestParam String endDate) {
        List<DeviceStep> steps = deviceStepService.getDaysStepInfo(deviceId, startDate, endDate);
        return ResultVO.success(steps);
    }

    /**
     * 同步 步数数据
     *
     * @return
     */
    @ApiOperation("同步 步数数据")
    @PostMapping("/synchronizationStep")
    public ResultVO<List<DeviceStep>> synchronizationStep(@RequestBody SynchronizationStepDto dao) {
        List<DeviceStep> deviceSteps = deviceStepService.synchronizationStep(dao.getDeviceSteps());
        return ResultVO.success(deviceSteps);
    }


}
